﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace RecipeManager
{
    [Serializable]
    public class IngredientUsage : ICloneable
    {
        public IngredientUsage()
            : this("")
        {

        }
        public IngredientUsage(string ingredientName)
        {
            IngredientName = ingredientName;
        }

        // use 2 liter of Milk
        [XmlAttribute]
        public string Amount { get; set; }
        [XmlAttribute]
        public string Unit { get; set; }

        [XmlAttribute]
        public string IngredientName
        {
            get { return IngredientObject == null ? "" : IngredientObject.Name; }
            set
            {
                if (IngredientObject == null)
                {
                    IngredientObject = new Ingredient();
                }
                IngredientObject.Name = value;
            }
        }
        [XmlIgnore]
        public Ingredient IngredientObject { get; set; }
        [XmlAttribute]
        public string Category { get; set; }

        [XmlAttribute]
        #region AdditionalInfo

        public string AdditionalInfo { get; set; }

        #endregion

        #region ICloneable Member

        public object Clone()
        {
            IngredientUsage result = new IngredientUsage();

            result.Category = Category;
            result.Amount = Amount;
            result.Unit = Unit;
            result.IngredientObject = IngredientObject.Clone() as Ingredient;
            result.AdditionalInfo = AdditionalInfo;

            return result;
        }

        #endregion
    }
}
